/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Sep 23, 2013  3:10:43 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.database.dao.impl
 * File Name : ServicesDao.java
 * TODO
 */
package com.tis.database.dao.impl;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.tis.database.dao.ClsInstance;
import com.tis.database.dao.ServicesDao;

import promis.utility.CommonService;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Sep 23, 2013 : 3:10:43 PM 
 * CreateBy=Chatree Siangklom
 * TODO
 */
@Repository
@SuppressWarnings("unchecked")
public class ServicesDaoImpl extends AbstractDaoImpl<VwSyncSeq, BigDecimal> implements ServicesDao {

	/**
	 * Date =Sep 23, 2013 : 3:44:49 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 * @param entityClass
	 */
	protected ServicesDaoImpl() {
		super(VwSyncSeq.class);
	}

	/** (Javadoc)
	 * @see com.tis.database.dao.ServicesDao#SeqNext()
	 * Date =Sep 23, 2013 : 3:44:52 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public BigDecimal SeqNext() throws HibernateException, Exception {

		try {
			
			Session session = getCurrentSession();
			/* Native-SQL */
			Query sqlQuery = session.createSQLQuery("Select "+ ClsInstance.PROMIS_SCHEMA + ClsInstance.POINTER + "VW_SYNC_SEQ.nextval as next_seq from dual ").addEntity(VwSyncSeq.class);
			List results = sqlQuery.list();
			System.out.println("results size=" + CommonService.getSize(results));			
			
			if(CommonService.getSize(results) > 0) {
				List<VwSyncSeq> lst = Collections.checkedList(results, VwSyncSeq.class);
				
				for(VwSyncSeq model : lst)
					System.out.println("SeqNext =" + CommonService.IsNullRString(model.getNext_seq()));
				
			}
		}catch(HibernateException e1) {
			e1.printStackTrace();
		}catch(Exception e2) {
			e2.printStackTrace();
		}
		
		return new BigDecimal("-1");
	}

}


